package cases 
{
	import cases.boxes.*;
	import com.sociodox.theminer.TheMiner;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.ui.Mouse;
	import flash.ui.MouseCursorData;
	import org.despair2D.control.KeyboardManager;
	import org.despair2D.control.MouseManager;
	import org.despair2D.control.ZMouseEvent;
	import org.despair2D.resource.EmbededUtil;
	import org.despair2D.StatsKai;
	import org.despair2D.ui.PersonaState;
	import org.despair2D.Despair;
	import org.despair2D.ui.Button;
	import org.despair2D.ui.CheckBox;
	import org.despair2D.ui.DespairUI;
	import org.despair2D.ui.events.SelectedEvent;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.LabelButton;
	import resource.Assets;
	import resource.AssetsUI;
	
	
	[SWF(width = '1024' ,height = '562', frameRate = '60')]
public class ButtonDemo extends Sprite 
{

	public function ButtonDemo() 
	{
		this.addEventListener(Event.ADDED_TO_STAGE, init)
	}
	
	private function init(e:Event):void
	{
		this.removeEventListener(Event.ADDED_TO_STAGE, init)
		
		// profiler
		//this.addChild(new TheMiner());
		this.addChild(new StatsKai)
		
		// "despair2d" start up !!
		Despair.startup(stage, 0.8);
		KeyboardManager.getInstance().initialize()
		
		// embed assets...
		var resourceList:Array
		var i:int, l:int
		
		resourceList = Assets.getAssetList().concat(AssetsUI.getAssetList())
		l = resourceList.length
		while (i < l)
		{
			EmbededUtil.loadBytes(resourceList[i++], onLoaded)
		}
		
		function onLoaded():void
		{
			if (EmbededUtil.index + 1 >= l)
			{
				_onLoadResource()
			}
		}
	}
	
	// 加载资源完毕
	private function _onLoadResource():void
	{
		// embed complete...
		EmbededUtil.dispose()
		
		// section...
		var sections:Array = Assets.getSectionXML()
		var i:int, l:int = sections.length
		while (i < l)
		{
			Despair.registerSections(XML(sections[i++]))
		}
		
		// cursor !!
		var bmd:BitmapData
		var m:MouseCursorData
		
		bmd = new AssetsUI.cursor().bitmapData;
		m = new MouseCursorData();
		m.data = Vector.<BitmapData>([bmd]);
		Mouse.registerCursor('aa', m);
		Mouse.cursor = 'aa';
		
		DespairUI.startup()
		DespairUI.createPersona(StartingState)
		
	}

}

}


